tar xf ${DOWNLOADDIR}/qemu-10.1.0.tar.xz -C ${BUILDDIR}
pushd ${BUILDDIR}/qemu-10.1.0
    sed -i "/HAVE_OPENAT2_H/d" meson.build
    mkdir build
    pushd build
        ../configure --prefix=${SYSDIR}/cross-tools --target-list=loongarch64-linux-user --disable-docs --static
        ninja
        cp qemu-loongarch64 ${SYSDIR}/cross-tools/bin/qemu-loongarch64.bin
    popd
popd

echo "#!/bin/bash -e
${SYSDIR}/cross-tools/bin/qemu-loongarch64.bin -L ${SYSDIR}/sysroot -E LD_LIBRARY_PATH=.libs:${SYSDIR}/sysroot/usr/lib64 \"\$@\"" \
> ${SYSDIR}/cross-tools/bin/qemu-loongarch64

echo "#!/bin/bash -e
${SYSDIR}/cross-tools/bin/qemu-loongarch64.bin -L ${SYSDIR}/sysroot -E LD_TRACE_LOADED_OBJECTS=1 -E LD_LIBRARY_PATH=${SYSDIR}/sysroot/usr/lib64 \"\$@\"" \
> ${SYSDIR}/cross-tools/bin/qemu-loongarch64-ldd

chmod +x ${SYSDIR}/cross-tools/bin/qemu-loongarch64{,-ldd}

